// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store';
import * as filters from './filters'; // 全局vue filter
import 'mint-ui/lib/style.css'

//remove before online
//import './mock/index.js'

Vue.config.productionTip = false

// register global utility filters.
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
});


router.beforeEach((to, from, next) => {
  // startsWith是个坑
  //if(to && !to.path.startsWith('/category/')){
  //  window._hmt.push(['_trackPageview', to.path]);
  //}
  // console.log("beforeEach:" + to.fullPath);
  var channel = store.getters.channel;
  var existQuery = to.query;
  if (!existQuery) {
    existQuery = {};
  }
  // 给每个url添加from参数
  if(!("from" in existQuery) && channel ) {
    existQuery["from"] = channel;
    next({ path: to.path, query: existQuery });
  } else {
    if(to && to.path && to.path.substr && to.path.length >= "/category/".length) {
      if(to.path.substr(0, "/category/".length) != "/category/") {
        window._hmt.push(['_trackPageview', to.fullPath]);
      }
    }
    next();
  }

});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
});
